package com.luna.serviceImpl;

import com.luna.beans.User;
import com.luna.dao.UserDao;
import com.luna.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    @Override
    public User login(String username, String password) {
        User user = null;
        UserDao userDao = new UserDao();
        try {
            user = userDao.selectByUserNameAndPassword(username, password);
        } catch (Exception ignored) {}
        return user;
    }

    @Override
    public User getUser(int user_id) {
        return null;
    }

    @Override
    public List<User> userList() {
        List<User> list = null;
        UserDao userDao = new UserDao();
        try {
            list = userDao.selectAllNormalUser();
        } catch (Exception ignored) {}
        return list;
    }

    @Override
    public boolean addUser(User user) {
        UserDao userDao = new UserDao();
        try {
            userDao.insertNormalUser(user);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    @Override
    public boolean dropUser(int user_id) {
        return false;
    }

    @Override
    public boolean updatePassword(String username, String password, String newPassword) {
        return false;
    }

    @Override
    public boolean restricted(int user_id, int state) {
        UserDao userDao = new UserDao();
        try {
            if (state == 0) {
                userDao.restrictUser(user_id);
            } else {
                userDao.unRestrictUser(user_id);
            }
        } catch (Exception _e) {
            return false;
        }
        return true;
    }
}
